package com.eportal.struts.action;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.eportal.ORM.MpayAccount;
import com.eportal.ORM.MpayFee;
import com.eportal.ORM.MpayUser;
import com.eportal.ORM.UserView;
import com.eportal.ORM.WtPepPayinfo;
import com.eportal.ORM.WtPepPayinfoId;
import com.eportal.ORM.WtZfxtInfo;
import com.eportal.core.BaseAction;
import com.eportal.core.Util;
import com.eportal.service.AdminService;

public class WapAction extends BaseAction {
	AdminService service;
	AdminService serviceOracle;
	private int start;
	private int page;

	private String password;
	private String newPassword;
	private String checkPassword;
	private String startDate;
	private String endDate;
	private String payinfo_key;
	private int payee;
	private String amount;
	private String fee;
	private String all_amount;
	private String ps;
	private String card;
	private String cardAgain;
	private String name;
	private String city;
	private String keywords;
	private String province;
	private String acc_type;
	private String bank_hh;

	public String getFee() {
		return fee;
	}

	public void setFee(String fee) {
		this.fee = fee;
	}

	public String getAll_amount() {
		return all_amount;
	}

	public void setAll_amount(String allAmount) {
		all_amount = allAmount;
	}

	public String getBank_hh() {
		return bank_hh;
	}

	public void setBank_hh(String bankHh) {
		bank_hh = bankHh;
	}

	public String getAcc_type() {
		return acc_type;
	}

	public void setAcc_type(String accType) {
		acc_type = accType;
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getCard() {
		return card;
	}

	public void setCard(String card) {
		this.card = card;
	}

	public String getCardAgain() {
		return cardAgain;
	}

	public void setCardAgain(String cardAgain) {
		this.cardAgain = cardAgain;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getKeywords() {
		return keywords;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}

	public String getAmount() {
		return amount;
	}

	public void setAmount(String amount) {
		this.amount = amount;
	}

	public String getPs() {
		return ps;
	}

	public void setPs(String ps) {
		this.ps = ps;
	}

	public int getPayee() {
		return payee;
	}

	public void setPayee(int payee) {
		this.payee = payee;
	}

	public String getPayinfo_key() {
		return payinfo_key;
	}

	public void setPayinfo_key(String payinfoKey) {
		payinfo_key = payinfoKey;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNewPassword() {
		return newPassword;
	}

	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}

	public String getCheckPassword() {
		return checkPassword;
	}

	public void setCheckPassword(String checkPassword) {
		this.checkPassword = checkPassword;
	}

	public AdminService getService() {
		return service;
	}

	public void setService(AdminService service) {
		this.service = service;
	}

	public AdminService getServiceOracle() {
		return serviceOracle;
	}

	public void setServiceOracle(AdminService serviceOracle) {
		this.serviceOracle = serviceOracle;
	}

	public String passwordwap() {
		LOG.info("手机修改密码");
		UserView mpay = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		MpayUser m = (MpayUser) service.loadById(MpayUser.class, mpay.getId());
		if (newPassword.equals("") || !newPassword.equals(checkPassword)) {
			this.getRequest().setAttribute("action", "modifyPasswordFailure");
			this.getRequest().setAttribute("message", "两次输入不一致!");
			return ERROR;
		} else {
			if (m.getMpayPassword().equals(password)) {
				m.setMpayPassword(newPassword);
				try {
					service.saveOrUpdate(m);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					this.getRequest().setAttribute("action",
							"modifyPasswordFailure");
					this.getRequest().setAttribute("message", "密码修改有误!");
					return ERROR;
				}
			} else {
				this.getRequest().setAttribute("action",
						"modifyPasswordFailure");
				this.getRequest().setAttribute("message", "原密码错误!");
				return ERROR;
			}
		}
		this.getRequest().setAttribute("message", "密码修改成功!");
		return SUCCESS;
	}

	public String serchPayinfo() {
		if (startDate == null)
			startDate = "";
		if (endDate == null)
			endDate = "";
		startDate = startDate.equals("") ? Util.getCurrentDate("yyyyMMdd")
				: startDate;
		endDate = endDate.equals("") ? Util.getCurrentDate("yyyyMMdd")
				: endDate;
		this.getRequest().setAttribute("startDate", startDate);
		this.getRequest().setAttribute("endDate", endDate);
		return SUCCESS;
	}

//	public String billList() {
//		LOG.info("手机_汇款单列表。。。");
//		UserView m = (UserView) getRequest().getSession().getAttribute(
//				"mpay_user");
//		String sql = "";
//		if (m.getIsAll() == 1) {
//			sql += " where '1'='1' ";
//		} else {
//			sql += " where PAY_ID = '" + m.getId() + "' ";
//		}
//		if (startDate == null)
//			startDate = "";
//		if (endDate == null)
//			endDate = "";
//		if (startDate.equals("") || endDate.equals("")) {
//			this.getRequest().setAttribute("action", "modifyPasswordFailure");
//			this.getRequest().setAttribute("message", "日期不能为空!");
//			return ERROR;
//		}
//		sql += "and  (pay_date between '" + startDate + "' and '" + endDate
//				+ "') ";
//		int count = serviceOracle
//				.countQuery("select count(*) from WtPepPayinfo" + sql);
//		if (count % 10 == 0)
//			page = count / 10;
//		else
//			page = count / 10 + 1;
//		if (start == 0)
//			start = 1;
//		if (start > page)
//			start = page;
//		// System.out.println(sql);
//		sql += " order by pay_date desc,pay_time desc ";
//		List userList = serviceOracle.query("from WtPepPayinfo" + sql, start,
//				10);
//		List tmp = new ArrayList();
//		for (int i = 0; i < userList.size(); i++) {
//			String msg = "";
//			WtPepPayinfo w = (WtPepPayinfo) userList.get(i);
//			String yd = w.getPayQs();
//			if (yd.equals("0")) {
//				yd = "成功";
//			} else if (yd.equals("1")) {
//				yd = "失败";
//			} else if (yd.equals("F")) {
//				yd = "已付款";
//			} else if (yd.equals("S")) {
//				yd = "已处理";
//			} else if (yd.equals("P")) {
//				yd = "待付款";
//			}
//			msg += w.getId().getPayDate() + "," + w.getId().getPayTrace() + ";"
//					+ w.getPayZfId() + "|" + w.getPayInName().trim() + "|"
//					+ (float) Integer.valueOf(w.getPayAmt()) / 100 + "|" + yd;
//			tmp.add(msg);
//		}
//		this.getRequest().setAttribute("startDate", startDate);
//		this.getRequest().setAttribute("endDate", endDate);
//		this.getRequest().setAttribute("list", tmp);
//		this.getRequest().setAttribute("count", count);
//		this.getRequest().setAttribute("page", page);
//		this.getRequest().setAttribute("start", start);
//		return SUCCESS;
//	}

//	public String getPaydetail() {
//		String trace = payinfo_key.split(",")[1].trim();
//		String zfid = payinfo_key.split(",")[0].trim();
//		WtPepPayinfo w;
//		try {
//			w = (WtPepPayinfo) serviceOracle.query(
//					"from WtPepPayinfo where trim(PAY_TRACE) = '" + trace
//							+ "' and trim(PAY_DATE) = '" + zfid + "' ").get(0);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//			this.getRequest().setAttribute("action", "modifyPasswordFailure");
//			this.getRequest().setAttribute("message", "读取详细信息错误!");
//			return ERROR;
//		}
//		String msg = "";
//		msg += w.getPayZfId() + ",";
//		msg += Util.toInCard(w.getPayInAccount().trim()) + ",";
//		msg += w.getPayInName().trim() + ",";
//		msg += w.getPayInBankName().trim() + ",";
//		msg += (float) Integer.valueOf(w.getPayAmt()) / 100 + ",";
//		msg += w.getPayRemark().trim() + ",";
//		String d = w.getId().getPayDate() + ",";
//		String tt = w.getPayTime() + ",";
//		msg += d.substring(0, 4) + "-" + d.substring(4, 6) + "-"
//				+ d.substring(6, 8) + " " + tt.substring(0, 2) + ":"
//				+ tt.substring(2, 4) + ":" + tt.substring(4, 6) + ",";
//		String yd = w.getPayQs();
//		if (yd.equals("0")) {
//			yd = "成功";
//		} else if (yd.equals("1")) {
//			yd = "失败";
//		} else if (yd.equals("F")) {
//			yd = "已付款";
//		} else if (yd.equals("S")) {
//			yd = "已处理";
//		} else if (yd.equals("P")) {
//			yd = "待付款";
//		}
//		msg += yd+",";
//		msg += (float) Integer.valueOf(w.getPayZfFee()) / 100+",";
//		msg += (float) Integer.valueOf(w.getPayAmt()) / 100 +(float) Integer.valueOf(w.getPayZfFee()) / 100+",";
//		this.getRequest().setAttribute("msg", msg);
//		this.getRequest().setAttribute("startDate", startDate);
//		this.getRequest().setAttribute("endDate", endDate);
//		this.getRequest().setAttribute("start", start);
//		return SUCCESS;
//	}

	public String sendRemitWapOne() {
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");

		List list = service.query("from MpayAccount where rcv_term = '"
				+ m.getId() + "' ");
		this.getRequest().setAttribute("list", list);
		return SUCCESS;
	}

	public String sendRemitWapTwo() {
		UserView user = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		MpayAccount m = (MpayAccount) service
				.loadById(MpayAccount.class, payee);
		if (m == null) {
			this.getRequest().setAttribute("action", "modifyPasswordFailure");
			this.getRequest().setAttribute("message", "读取收款人有误!");
			return ERROR;
		}
		m.setRcvTerm(user.getMpayUsername());
		this.getRequest().setAttribute("account", m);
		return SUCCESS;
	}

	public String sendRemitWapThree() {
		UserView user = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		MpayAccount m = (MpayAccount) service
				.loadById(MpayAccount.class, payee);
		m.setRcvTerm(user.getMpayUsername());
		try {
			amount = Float.valueOf(amount) + "";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			this.getRequest().setAttribute("action", "modifyPasswordFailure");
			this.getRequest().setAttribute("message", "金额输入有误!");
			return ERROR;
		}
		MpayFee feem = (MpayFee) service.loadById(MpayFee.class, user.getId());
		if (feem == null) {
			fee = "0";
			all_amount=amount;
		} else {
			try {
				float amt = Float.valueOf(amount);
				float f1 = Float.valueOf(feem.getFactor1());
				float f2 = Float.valueOf(feem.getFactor2());
				float f3 = Float.valueOf(feem.getFactor3());
				float fees = 0;
				if (feem.getFeesType().equals("01")) {// 比例计算
					if (f1 == 0) {
						// 使用条件1
						fees = amt * Float.valueOf(feem.getProportion1());
						if (!feem.getProportionUp1().equals("0")) {
							if (fees > Float.valueOf(feem.getProportionUp1())) {
								fees = Float.valueOf(feem.getProportionUp1());
							}
						}
					} else if (f2 == 0) {
						if (amt > f1) {
							// 使用条件2
							fees = amt * Float.valueOf(feem.getProportion2());
							if (!feem.getProportionUp2().equals("0")) {
								if (fees > Float
										.valueOf(feem.getProportionUp2())) {
									fees = Float
											.valueOf(feem.getProportionUp2());
								}
							}
						} else {
							// 使用条件1
							fees = amt * Float.valueOf(feem.getProportion1());
							if (!feem.getProportionUp1().equals("0")) {
								if (fees > Float
										.valueOf(feem.getProportionUp1())) {
									fees = Float
											.valueOf(feem.getProportionUp1());
								}
							}
						}
					} else if (f3 == 0) {
						if (amt > f2) {
							// 使用条件3
							fees = amt * Float.valueOf(feem.getProportion3());
							if (!feem.getProportionUp3().equals("0")) {
								if (fees > Float
										.valueOf(feem.getProportionUp3())) {
									fees = Float
											.valueOf(feem.getProportionUp3());
								}
							}
						} else if (amt > f1) {
							// 使用条件2
							fees = amt * Float.valueOf(feem.getProportion2());
							if (!feem.getProportionUp2().equals("0")) {
								if (fees > Float
										.valueOf(feem.getProportionUp2())) {
									fees = Float
											.valueOf(feem.getProportionUp2());
								}
							}
						} else {
							// 使用条件1
							fees = amt * Float.valueOf(feem.getProportion1());
							if (!feem.getProportionUp1().equals("0")) {
								if (fees > Float
										.valueOf(feem.getProportionUp1())) {
									fees = Float
											.valueOf(feem.getProportionUp1());
								}
							}
						}
					} else {
						if (amt > f3) {
							// 不计算
							return SUCCESS;
						} else {
							if (amt > f2) {
								// 使用条件3
								fees = amt
										* Float.valueOf(feem.getProportion3());
								if (!feem.getProportionUp3().equals("0")) {
									if (fees > Float.valueOf(feem
											.getProportionUp3())) {
										fees = Float.valueOf(feem
												.getProportionUp3());
									}
								}
							} else if (amt > f1) {
								// 使用条件2
								fees = amt
										* Float.valueOf(feem.getProportion2());
								if (!feem.getProportionUp2().equals("0")) {
									if (fees > Float.valueOf(feem
											.getProportionUp2())) {
										fees = Float.valueOf(feem
												.getProportionUp2());
									}
								}
							} else {
								// 使用条件1
								fees = amt
										* Float.valueOf(feem.getProportion1());
								if (!feem.getProportionUp1().equals("0")) {
									if (fees > Float.valueOf(feem
											.getProportionUp1())) {
										fees = Float.valueOf(feem
												.getProportionUp1());
									}
								}
							}
						}
					}
					fee = fees + "";
					all_amount = fees+amt+"";
				} else if (feem.getFeesType().equals("02")) {// 固定计算
					if (f1 == 0) {
						// 使用条件1
						fees = Float.valueOf(feem.getProportion1());
					} else if (f2 == 0) {
						if (amt > f1) {
							// 使用条件2
							fees = Float.valueOf(feem.getProportion2());
						} else {
							// 使用条件1
							fees = Float.valueOf(feem.getProportion1());
						}
					} else if (f3 == 0) {
						if (amt > f2) {
							// 使用条件3
							fees = Float.valueOf(feem.getProportion3());
						} else if (amt > f1) {
							// 使用条件2
							fees = Float.valueOf(feem.getProportion2());
						} else {
							// 使用条件1
							fees = Float.valueOf(feem.getProportion1());
						}
					} else {
						if (amt > f3) {
							// 不计算
							return SUCCESS;
						} else {
							if (amt > f2) {
								// 使用条件3
								fees = Float.valueOf(feem.getProportion3());
							} else if (amt > f1) {
								// 使用条件2
								fees = Float.valueOf(feem.getProportion2());
							} else {
								// 使用条件1
								fees = Float.valueOf(feem.getProportion1());
							}
						}
					}
					fee = fees + "";
					all_amount = fees+amt+"";
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				this.getRequest().setAttribute("action", "modifyPasswordFailure");
				this.getRequest().setAttribute("message", "计算手续费出错!");
				return ERROR;
			}
			
		}
		this.getRequest().setAttribute("account", m);
		this.getRequest().setAttribute("amount", amount);
		this.getRequest().setAttribute("fee", fee);
		this.getRequest().setAttribute("all_amount", all_amount);
		this.getRequest().setAttribute("ps", ps);
		return SUCCESS;
	}

	public String sendRemitWapFour() throws Exception {
		this.getRequest().setAttribute("amount", amount);
		this.getRequest().setAttribute("fee", fee);
		this.getRequest().setAttribute("all_amount", all_amount);
		this.getRequest().setAttribute("ps",
				new String(ps.getBytes("ISO-8859-1"), "UTF-8"));
		this.getRequest().setAttribute("payee", payee + "");
		return SUCCESS;
	}

//	public String sendRemitFin() throws Exception {
//		LOG.info("发送汇款...");
//		UserView mpay = (UserView) getRequest().getSession().getAttribute(
//				"mpay_user");
//		MpayAccount ca = (MpayAccount) service.loadById(MpayAccount.class,
//				payee);
//		WtPepPayinfo w = new WtPepPayinfo();
//		WtPepPayinfoId wid = new WtPepPayinfoId();
//		w.setPayAmt(Util.getAMT(Util.moveRightTwo(amount)));
//		w.setPayZfFee(Util.getFEE(Util.moveRightTwo(fee)));
//		w.setPayAprespn("FF");
//		w.setPayId(mpay.getId() + "");
//		w.setPayInAccount(ca.getRcvCdno());
//		w.setPayInBankCode(ca.getRcvBankno());
//		w.setPayInBankName(ca.getRcvBankname().trim());
//		w.setPayInName(ca.getRcvName());
//		w.setPayInType(ca.getRcvType());
//		w.setPayMerCode("");
//		w.setPayOutAccount("10133061612731345000820002");
//		w.setPayOutBankName("杭州建行宝石支行");
//		w.setPayOutXy("3310110501X2");
//		w.setPayPhone(ca.getRcvMobile());
//		w.setPayQs("P");
//		w.setPayRemark(ps == null || ps.equals("") ? "汇款" : new String(ps
//				.getBytes("ISO-8859-1"), "UTF-8"));
//		w.setPayTerCode("");
//		w.setPaySendDate(new Timestamp(new Date().getTime()));
//		w.setPayTime(Util.getCurrentDate("HHmmss"));
//		wid.setPayTrace(Util.addZero(getTrace() + "", 6));
//		wid.setPayDate(Util.getCurrentDate("yyyyMMdd"));
//		String payid = Util.getCurrentDate("MMdd")
//				+ Util.addZero(getPayTrace() + "", 6);
//		w.setPayZfId(payid);
//		w.setId(wid);
//		try {
//			// LOG.info("立刻发生汇款单_" + wid.getPayTrace());
//			serviceOracle.saveOrUpdate(w);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//			this.getRequest().setAttribute("action", "modifyPasswordFailure");
//			this.getRequest().setAttribute("message", "汇款单发送错误!");
//			return ERROR;
//		}
//		try {
//			Util.sendSMS("汇款单号:" + payid + ",收款人:" + ca.getRcvName() + ",汇款金额:"
//					+ amount + ",手续费" + fee + "元,请在终端上支付。", mpay
//					.getMpayTermid());
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		this.getRequest().setAttribute("message",
//				"汇款单生成成功!<br>" + "汇款单号:" + payid + ",<br>请在终端上支付。");
//		return SUCCESS;
//	}

	public String payeeList() {
		LOG.info("手机_联系人列表。。。");
		if (this.getRequest().getParameter("addpage") != null) {
			return "addPayee";
		}
		if (this.getRequest().getParameter("deletepage") != null) {
			MpayAccount m = (MpayAccount) service.loadById(MpayAccount.class,
					payee);
			this.getRequest().setAttribute("account", m);
			return "deletePayee";
		}
		if (this.getRequest().getParameter("delete") != null) {
			try {
				service.delById(MpayAccount.class, payee);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				this.getRequest().setAttribute("action",
						"modifyPasswordFailure");
				this.getRequest().setAttribute("message", "删除收款人错误!");
				return ERROR;
			}
		}
		UserView m = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		String sql = "";
		sql += " where RCV_term = '" + m.getId() + "' ";
		int count = service
				.countQuery("select count(*) from MpayAccount" + sql);
		if (count % 10 == 0)
			page = count / 10;
		else
			page = count / 10 + 1;
		if (start == 0)
			start = 1;
		if (start > page)
			start = page;
		// System.out.println(sql);
		sql += " order by rcv_date desc ";
		List userList = service.query("from MpayAccount" + sql, start, 10);
		List tmp = new ArrayList();
		for (int i = 0; i < userList.size(); i++) {
			String msg = "";
			MpayAccount w = (MpayAccount) userList.get(i);
			msg += w.getId() + ";" + w.getRcvName() + "|"
					+ Util.toInCard(w.getRcvCdno()) + "|" + w.getRcvBankname();
			tmp.add(msg);
		}
		this.getRequest().setAttribute("list", tmp);
		this.getRequest().setAttribute("count", count);
		this.getRequest().setAttribute("page", page);
		this.getRequest().setAttribute("start", start);
		return SUCCESS;

	}

	public String addPayeeOne() {
		if (card == null || cardAgain == null || card.equals("")
				|| cardAgain.equals("")) {
			this.getRequest().setAttribute("action", "addFailure");
			this.getRequest().setAttribute("message", "卡号不能为空！");
			return ERROR;
		}
		if (!card.equals(cardAgain)) {
			this.getRequest().setAttribute("action", "addFailure");
			this.getRequest().setAttribute("message", "两次输入不一致！");
			return ERROR;
		}
		if (name == null || name.equals("")) {
			this.getRequest().setAttribute("action", "addFailure");
			this.getRequest().setAttribute("message", "收款人户名不能为空！");
			return ERROR;
		}
		this.getRequest().setAttribute("card", card);
		this.getRequest().setAttribute("name", name);
		this.getRequest().setAttribute("acc_type", acc_type);
		return SUCCESS;
	}

	public String addPayeeTwo() {
		if (city == null || city.equals("")) {
			this.getRequest().setAttribute("action", "addFailure");
			this.getRequest().setAttribute("message", "城市名称不能为空！");
			return ERROR;
		}
		System.out.println(" from WtZfxtInfo where ZFXT_CYZQC like '%"
				+ province + "%" + city.trim() + "%" + keywords + "%'");
		List list = serviceOracle
				.query(" from WtZfxtInfo where ZFXT_CYZQC like '%" + province
						+ "%" + city.trim() + "%" + keywords + "%'");
		this.getRequest().setAttribute("list", list);
		this.getRequest().setAttribute("name", name);
		this.getRequest().setAttribute("card", card);
		this.getRequest().setAttribute("acc_type", acc_type);
		return SUCCESS;
	}

	public String addPayeeThree() throws Exception {
		this.getRequest().setAttribute("name",
				new String(name.getBytes("ISO-8859-1"), "UTF-8"));
		this.getRequest().setAttribute("card",
				new String(card.getBytes("ISO-8859-1"), "UTF-8"));
		this.getRequest().setAttribute("acc_type",
				new String(acc_type.getBytes("ISO-8859-1"), "UTF-8"));
		this.getRequest().setAttribute("bank_hh",
				new String(bank_hh.getBytes("ISO-8859-1"), "UTF-8"));
		return SUCCESS;
	}

	public String addPayeeFin() throws Exception {
		UserView mpay = (UserView) getRequest().getSession().getAttribute(
				"mpay_user");
		name = new String(name.getBytes("ISO-8859-1"), "UTF-8");
		card = new String(card.getBytes("ISO-8859-1"), "UTF-8");
		acc_type = new String(acc_type.getBytes("ISO-8859-1"), "UTF-8");
		bank_hh = new String(bank_hh.getBytes("ISO-8859-1"), "UTF-8");
		System.out.println(" from WtZfxtInfo where trim(ZFXT_CYZQC) = '"
				+ bank_hh + "'");
		List list = serviceOracle
				.query(" from WtZfxtInfo where trim(ZFXT_CYZQC) = '" + bank_hh
						+ "'");
		if (list.size() == 0) {
			this.getRequest().setAttribute("action", "addFailure");
			this.getRequest().setAttribute("message", "添加收款人失败！");
			return ERROR;
		}
		WtZfxtInfo w = (WtZfxtInfo) list.get(0);
		MpayAccount ca = new MpayAccount();
		ca.setRcvBankjx("");
		ca.setRcvBankname(w.getId().getZfxtCyzqc());
		ca.setRcvBankno(w.getId().getZfxtHh());
		ca.setRcvDate(Util.getCurrentDate("yyyy-MM-dd HH:mm:ss"));
		ca.setRcvFlag("0");
		ca.setRcvName(name);
		ca.setRcvMobile("");
		if (acc_type.equals("活期储蓄存折"))
			acc_type = "1";
		else if (acc_type.equals("对公帐户"))
			acc_type = "2";
		else if (acc_type.equals("借记卡"))
			acc_type = "3";
		else if (acc_type.equals("信用卡"))
			acc_type = "4";
		else if (acc_type.equals("活期存款账户"))
			acc_type = "5";
		else
			acc_type = "0";
		ca.setRcvType(acc_type);
		ca.setRcvCdno(card);
		ca.setRcvMerCode("");
		ca.setRcvTermCode("");
		ca.setRcvTerm(mpay.getId() + "");
		try {
			service.save(ca);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			this.getRequest().setAttribute("action", "addFailure");
			this.getRequest().setAttribute("message", "添加收款人失败！,请查看是否重复");
			return ERROR;
		}
		this.getRequest().setAttribute("message", "收款人添加成功！");
		return SUCCESS;
	}

//	public int getTrace() {
//		int i = 0;
//		List tmp = serviceOracle
//				.query(" from WtPepPayinfo order by to_number(pay_trace) desc ");
//		if (tmp.size() > 0) {
//			WtPepPayinfo w = (WtPepPayinfo) tmp.get(0);
//			i = Integer.valueOf(w.getId().getPayTrace().trim());
//		}
//		i += 1;
//		if (i == 999999)
//			i = 1;
//		return i;
//	}

//	public int getPayTrace() {
//		int i = 0;
//		List tmp = serviceOracle
//				.query(" from WtPepPayinfo where pay_zf_id is not null order by to_number(pay_zf_id) desc ");
//		if (tmp.size() > 0) {
//			WtPepPayinfo w = (WtPepPayinfo) tmp.get(0);
//			// System.out.println(w.getPayZfId()+" "+w.getPayZfId().substring(4));
//			if (w.getPayZfId() != null && !w.getPayZfId().equals("")) {
//				i = Integer.valueOf(w.getPayZfId().substring(4));
//			}
//		}
//		i += 1;
//		if (i == 999999)
//			i = 1;
//		return i;
//	}
}
